<template>
  <div class="layout-my" v-cloak>
    <van-nav-bar class="my-bar" title="个人中心" :border="false" />
    <div class="my-box">
      <div class="user-title">
        <div class="user-haed">{{ head }}</div>
        <div class="user-right">
          <div>
            <span>{{ userName.userName }}</span>
            <span>{{ realName === 1 ? '已实名' : '未实名' }}</span>
          </div>
          <div>{{ userName.mobile }}</div>
        </div>
      </div>
      <van-cell class="my-cell" title="印章签名管理" is-link to="/station">
        <van-icon slot="icon" class-prefix="iconfont iconmyyinzhang" />
      </van-cell>
      <van-cell
        class="my-cell"
        title="常用联系人"
        is-link
        to="/frequent-contacts/5"
      >
        <van-icon slot="icon" class-prefix="iconfont iconmylianxiren" />
      </van-cell>
      <van-cell class="my-cell" title="扫一扫" is-link>
        <van-icon slot="icon" class-prefix="iconfont iconmysaosao" />
      </van-cell>
      <van-cell class="my-cell" title="在线客服" is-link>
        <van-icon slot="icon" class-prefix="iconfont iconmy" />
      </van-cell>
      <van-button class="btn-end" type="default" block @click="quit"
        >退出登录</van-button
      >
    </div>
  </div>
</template>

<script>
import { realNameAuthentication } from '@/api/user'
import { removeItem } from '@/utils/storage'
export default {
  data() {
    return {
      userName: [],
      head: '',
      realName: 1
    }
  },
  created() {
    this.initialList()
    this.userName = this.$store.state.userName
    this.head = this.userName.userName.split('')[0]
  },
  mounted() {},
  methods: {
    async initialList() {
      try {
        const { data: res } = await realNameAuthentication(
          this.$store.state.userName.idNumber
        )
        if (res.code !== '0') {
          return this.$toast.fail(res.msg)
        }
        if (res.data === '实名已通过') {
          this.realName = 1
        } else {
          this.realName = 0
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 退出登录
    quit() {
      removeItem('TOUTIAO_USER')
      removeItem('user')
      this.$store.commit('deleteAll')
      this.$router.push('/')
    }
  }
}
</script>

<style scoped lang="less">
.layout-my {
  overflow: hidden;
  height: 100vh;
  background-color: #f8f8f8;
  .my-bar {
    height: 88px;
    box-sizing: border-box;
    /deep/.van-ellipsis {
      font-size: 34px;
      font-weight: bold;
    }
  }
  .my-box {
    padding: 24px 40px 0 40px;
    .user-title {
      height: 220px;
      background-color: #fff;
      margin-bottom: 24px;
      display: flex;
      align-items: center;
      .user-haed {
        height: 108px;
        width: 108px;
        text-align: center;
        line-height: 108px;
        font-size: 38px;
        background-color: #2489f2;
        border-radius: 50%;
        margin: 0 31px 0 40px;
        color: #fff;
      }
      .user-right {
        div:nth-child(1) {
          span:nth-child(1) {
            font-size: 34px;
            vertical-align: bottom;
          }
          span:nth-child(2) {
            padding: 8px 11px;
            font-size: 24px;
            border: 1px solid #22c58d;
            color: #22c58d;
            margin-left: 32px;
            border-radius: 10px;
          }
        }
        div:nth-child(2) {
          font-size: 28px;
          color: #999999;
          margin-top: 19px;
        }
      }
    }
    .btn-card {
      position: absolute;
      top: 64px;
      left: 98px;
      font-size: 24px;
      width: 92px;
      height: 40px;
    }
    .van-button--normal {
      padding: 0;
      border-radius: 8px;
    }
    .van-cell {
      height: 120px;
      padding: 45px 32px;
      .iconfont {
        font-size: 30px;
        padding-right: 26px;
      }
    }
    .van-card__desc {
      font-size: 28px;
    }
    .btn-end {
      margin-top: 24px;
    }
    .van-button--default {
      border-width: 0;
      border: 0;
    }
  }
}
</style>
